package com.ryder.petmatediarybackend.common.enums;

import lombok.Getter;

/**
 * 描述: 响应结果枚举
 *
 * @author Ryder
 * @version 1.0
 * @since 1.0
 * 更新日期: 2025/10/25
 */
@Getter
public enum ResultCodeEnum {

    SUCCESS(200, "成功"),
    FAIL(500, "系统异常"),
    PARAM_ERROR(400, "请求参数错误"),
    UNAUTHORIZED(401, "未授权"),
    FORBIDDEN(403, "禁止访问"),
    NOT_FOUND(404, "请求的资源不存在"),

    // 自定义业务错误
    USER_EXIST(1001, "用户已存在"),
    LOGIN_FAIL(1002, "登录失败"),
    VALIDATE_CODE_ERROR(1003, "验证码错误"),
    NO_PERMISSION(1004, "无操作权限");

    private final int code;
    private final String desc;

    ResultCodeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ResultCodeEnum getByCode(int codeVal) {
        for (ResultCodeEnum resultCodeEnum : ResultCodeEnum.values()) {
            if (resultCodeEnum.getCode() == codeVal) {
                return resultCodeEnum;
            }
        }
        return null;
    }
}
